class jgEventBus {
  constructor() {
    this.eventBus = {}
  }
  on(eventName,eventCallback,thisArg) {
    let handlers = this.eventBus[eventName]
    if(!handlers) {
      handlers = []
      this.eventBus[eventName] = handlers
    }
    handlers.push({
      eventCallback,
      thisArg
    })
  }
  emit(eventName,...arge) {
    const handlers = this.eventBus[eventName]
    if(!handlers) return
    handlers.forEach(item => {
      item.eventCallback.apply(item.thisArg,arge)
    })
  }
  off(eventName,eventCallback) {
    const handlers = this.eventBus[eventName]
    if(!handlers) return
    const arrTask = [...handlers]
    for(let i=0;i<arrTask.length;i++) {
      if (arrTask[i].eventCallback === eventCallback) {
        handlers.splice(i,1)
      }
    }
  }
}

const bus = new jgEventBus()

bus.on('abc',function(a) {
  console.log('我监听到了abc1,参数为',a,this);
},{name:"金哥"})

function jjj(a) {
  console.log('我监听到了abc2,参数为',a,this);
}
bus.on('abc',jjj,{age:18})
// bus.off('abc',jjj)  卸载一个函数
bus.emit('abc',"金哥牛逼")